import { createRouter, createWebHashHistory } from "vue-router";
import NProgress from "@/config/nprogress";
import { staticRouter, errorRouter } from "@/routers/modules/staticRouter";

const router = createRouter({
  history: createWebHashHistory(),
  routes: [...staticRouter, ...errorRouter],
  strict: false,
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 路由拦截
router.beforeEach(async (to, from, next) => {
  NProgress.start();
  next();
});

// 路由跳转结束
router.afterEach(() => {
  NProgress.done();
});

// 路由跳转错误
router.onError((error) => {
  NProgress.done();
  console.warn("路由错误", error.message);
});

export default router;
